/**
//用两个栈实现一个队列。队列的声明如下，请实现它的两个函数 appendTail 和 deleteHead ，分别完成在队列尾部插入整数和在队列头部删除整数的
//功能。(若队列中没有元素，deleteHead 操作返回 -1 ) 
//
// 
//
// 示例 1： 
//
// 输入：
//["CQueue","appendTail","deleteHead","deleteHead"]
//[[],[3],[],[]]
//输出：[null,null,3,-1]
// 
//
// 示例 2： 
//
// 输入：
//["CQueue","deleteHead","appendTail","appendTail","deleteHead","deleteHead"]
//[[],[],[5],[2],[],[]]
//输出：[null,-1,null,null,5,2]
// 
//
// 提示： 
//
// 
// 1 <= values <= 10000 
// 最多会对 appendTail、deleteHead 进行 10000 次调用 
// 
// Related Topics 栈 设计 队列 👍 302 👎 0

*/

package com.xixi.easy;

import java.util.Stack;

public class ID_Offer_09_YongLiangGeZhanShiXianDuiLieLcof {
public static void main(String[] args) {
    CQueue cQueue = new ID_Offer_09_YongLiangGeZhanShiXianDuiLieLcof().new CQueue();
}


//leetcode submit region begin(Prohibit modification and deletion)
class CQueue {
    private Stack<Integer> stack_in;
    private Stack<Integer> stack_out;
    private boolean dataAtInStack = true;

    public CQueue() {
        stack_in = new Stack<>();
        stack_out = new Stack<>();
    }

    public void appendTail(int value) {
        if(!dataAtInStack){ //当数据在出队栈stack_out, 先把数据移动到入队栈stack_in
            moveDATA(stack_in, stack_out);
            dataAtInStack = true; //数据在入队栈
        }
        stack_in.push(value);
    }

    public int deleteHead() {
        if(stack_in.isEmpty() && stack_out.isEmpty()) return -1;

        if(dataAtInStack){ //当数据在出队栈stack_out, 先把数据移动到入队栈stack_in
            moveDATA(stack_out, stack_in);
            dataAtInStack = false; //数据在入队栈
        }
        return stack_out.pop();
    }

    public void moveDATA(Stack<Integer> dataIn, Stack<Integer> dataOut){
        while(!dataOut.isEmpty()){
            dataIn.push(dataOut.pop());
        }
    }

}

/**
 * Your CQueue object will be instantiated and called as such:
 * CQueue obj = new CQueue();
 * obj.appendTail(value);
 * int param_2 = obj.deleteHead();
 */
//leetcode submit region end(Prohibit modification and deletion)




}